package com.travel.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.travel.common.Result;
import com.travel.domain.VO.BannerVO;
import com.travel.domain.VO.CategoryVO;
import com.travel.domain.entity.Image;
import com.travel.domain.entity.Scene;
import com.travel.domain.entity.SceneInfo;
import com.travel.service.IndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexService indexService;
    @GetMapping("/banner")
    public Result<List<BannerVO>> getBanner(){
        LambdaQueryWrapper<Image> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Image::getType,"banner");
        List<Image> list = indexService.list(wrapper);
        List<BannerVO> bannerList = list.stream().map(image -> new BannerVO(image.getUrl(),image.getDescription())).toList();
        return Result.success(bannerList);
    }
    @GetMapping("/category")
    public Result<List<CategoryVO>> getCategory(){
        LambdaQueryWrapper<Image> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Image::getType,"category");
        List<Image> list = indexService.list(wrapper);
        List<CategoryVO> categoryList = list.stream().map(image -> new CategoryVO(image.getUrl(),image.getDescription())).toList();
        return Result.success(categoryList);
    }
    @GetMapping("/scene")
    public Result<List<Scene>> getScenes(){
        List<Scene> list = indexService.selectAllScene();
        return Result.success(list);
    }
    @GetMapping("/sceneInfo/{id}")
    public Result<SceneInfo> getSceneInfo(@PathVariable Long id){
        SceneInfo  sceneInfo = indexService.selectSceneInfo(id);
        return Result.success(sceneInfo);
    }
}
